package com.hexseek.libretvcloud.utils;

import java.util.*;

public class RandomHttpHeadersUtil {

    private static final List<String> USER_AGENTS = List.of(
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15",
            "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36",
            "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0"
    );

    private static final List<String> ACCEPT_LANGUAGES = List.of(
            "en-US,en;q=0.9",
            "zh-CN,zh;q=0.9",
            "en-GB,en;q=0.8",
            "fr-FR,fr;q=0.7,en;q=0.3"
    );

    private static final List<String> REFERERS = List.of(
            "https://www.google.com/",
            "https://www.bing.com/",
            "https://www.yahoo.com/",
            "https://duckduckgo.com/"
    );

    private static final Random RANDOM = new Random();

    public static Map<String, String> generateRandomHeaders() {
        Map<String, String> headers = new HashMap<>();
        headers.put("User-Agent", getRandom(USER_AGENTS));
        headers.put("Accept-Language", getRandom(ACCEPT_LANGUAGES));
        headers.put("Referer", getRandom(REFERERS));
        headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        headers.put("Connection", "keep-alive");
        headers.put("Upgrade-Insecure-Requests", "1");
        headers.put("Cache-Control", "no-cache");
        headers.put("Pragma", "no-cache");
        return headers;
    }

    private static <T> T getRandom(List<T> list) {
        return list.get(RANDOM.nextInt(list.size()));
    }
}

